<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
	
	$lang = $_SESSION['lang'];
	if (empty($lang) || $lang == "EN") {
		include "../value/value_en.php";
	} else if($lang == "VN") {
		include "../value/value_vn.php";
	}
	else {
		include "../value/value_kr.php";
	}


if (isset($_SESSION['emsa'])) {
	
	//include '../Classes/PHPExcel.php';
	/** Include path **/
	set_include_path(get_include_path() . PATH_SEPARATOR . 'ClassesExcel/');
	
	/** PHPExcel */
	require_once 'PHPExcel.php';
	
	/** PHPExcel_RichText */
	require_once 'PHPExcel/RichText.php';
	
	
	$filename =$l_employee_salaries." ".$_REQUEST['month']."/".$_REQUEST['year'].".xls";
	
	$contents = "l_employee_name \t l_position \t l_number_time_work \t l_num_allow_holiday \t l_basicsalary \t l_allowancebasicsalary \t l_dayoff \t l_absentmonth \t l_comebackearly \t l_comelately \t l_allowanceSenior \t l_allowanceC \t l_salaryperday \t l_salaryreceived \t l_allowance_holiday \t l_lunch \t l_parking \t l_allowance_hard \t l_numbersession \t l_total_amount \t l_total \t l_socialInsurance \t l_salary_bonus \t l_salary_sub \t l_realreceived \t l_note \t \n";
	$objPHPExcel = new PHPExcel();

	
	$styleArray = array(
		'font' => array(
			'bold' => true,
			'size' => 11,
		),
		'alignment' => array(
			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
			'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
			'wrap' => true,
		),
		'borders' => array(
			'top' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'bottom' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'left' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'right' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
		),
		'fill' => array(
			'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
			'rotation' => 90,
			'startcolor' => array(
				'argb' => 'FFA0A0A0',
			),
			'endcolor' => array(
				'argb' => 'FFFFFFFF',
			),
		),
	);
	$styleArray1 = array(
		'font' => array(
			'bold' => true,
			'size' => 11,
		),
		'alignment' => array(
			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
			'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
			'wrap' => true,
		),
		'borders' => array(
			'top' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'bottom' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'left' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'right' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
		),
		
	);
	$styleArray2 = array(
			'alignment' => array(
			'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
			'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
			'wrap' => true,
		),
		'borders' => array(
			'top' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'bottom' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'left' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
			'right' => array(
				'style' => PHPExcel_Style_Border::BORDER_THIN,
			),
		),
		
	);
	/*$objPHPExcel->getProperties()->setCreator('Matthew Casperson')
	->setLastModifiedBy('Matthew Casperson')
	->setTitle('Office 2007 XLSX Test Document')
	->setSubject('Office 2007 XLSX Test Document')
	->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.');
	
	
	$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');
	$objPHPExcel->getDefaultStyle()->getFont()->setSize(8); */
	
	$objPHPExcel->setActiveSheetIndex(0);
	
	$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName('Times New Roman');
	$objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
	$objPHPExcel->getActiveSheet()->mergeCells('A2:Y2');
	$objPHPExcel->getActiveSheet()->getStyle('A2')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->setCellValue('A2', $l_employee_salaries." ".$_REQUEST['month']."/".$_REQUEST['year']);
	
	$objPHPExcel->getActiveSheet()->freezePane('A6');
	
	$objPHPExcel->getActiveSheet()->getRowDimension('4')->setRowHeight(40);
	$objPHPExcel->getActiveSheet()->getStyle('A4')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('A4', $l_employee_name);
	
	$objPHPExcel->getActiveSheet()->getStyle('B4')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('B4', $l_department);
	
	$objPHPExcel->getActiveSheet()->getStyle('C4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('C4', $l_number_time_work);
	
	//$objPHPExcel->getActiveSheet()->getStyle('D4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
	//$objPHPExcel->getActiveSheet()->setCellValue('D4', $l_num_allow_holiday);
	
	$objPHPExcel->getActiveSheet()->getStyle('D4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('D4', $l_basicsalary);
	
	$objPHPExcel->getActiveSheet()->getStyle('E4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('E4', $l_allowancebasicsalary);
	
	$objPHPExcel->getActiveSheet()->getStyle('F4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('F4', $l_dayoff);
	
	$objPHPExcel->getActiveSheet()->getStyle('G4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('G4', $l_absentmonth);
	
	$objPHPExcel->getActiveSheet()->getStyle('H4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('H4', $l_comebackearly);
	
	$objPHPExcel->getActiveSheet()->getStyle('I4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('I4', $l_comelately);
	
	
	$objPHPExcel->getActiveSheet()->getStyle('J4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('U')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
	$objPHPExcel->getActiveSheet()->setCellValue('J4', $l_allowance_longyear);
	
	$objPHPExcel->getActiveSheet()->getStyle('K4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('K4', $l_allowanceSenior);
	
	$objPHPExcel->getActiveSheet()->getStyle('L4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('L4', $l_allowanceC);
	
	$objPHPExcel->getActiveSheet()->getStyle('M4')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(12);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('M4', $l_salaryperday);
	
	$objPHPExcel->getActiveSheet()->getStyle('N4')->applyFromArray($styleArray);
	$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(11);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('N4', $l_salaryreceived);
	
	$objPHPExcel->getActiveSheet()->getStyle('O4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('O4', $l_allowance_holiday);
	
	$objPHPExcel->getActiveSheet()->getStyle('P4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('P4', $l_lunch);
	
	$objPHPExcel->getActiveSheet()->getStyle('Q4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('Q4', $l_parking);
	
	$objPHPExcel->getActiveSheet()->getStyle('R4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('R4', $l_allowance_hard);
	
	$objPHPExcel->getActiveSheet()->getStyle('S4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('S4', $l_numbersession);
	
	$objPHPExcel->getActiveSheet()->getStyle('T4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(11);
	$objPHPExcel->getActiveSheet()->setCellValue('T4', $l_total_amount);
	
	
	
	$objPHPExcel->getActiveSheet()->getStyle('U4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('U')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(12);
	$objPHPExcel->getActiveSheet()->setCellValue('U4', $l_total);
	
	$objPHPExcel->getActiveSheet()->getStyle('V4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('V')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('V4', $l_socialInsurance);
	
	$objPHPExcel->getActiveSheet()->getStyle('W4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('X')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(12);
	$objPHPExcel->getActiveSheet()->setCellValue('W4', $l_realreceived);
	
	$objPHPExcel->getActiveSheet()->getStyle('X4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('X4', $l_note);
	
	$objPHPExcel->getActiveSheet()->getStyle('Y4')->applyFromArray($styleArray);
	//$objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setAutoSize(true);
	$objPHPExcel->getActiveSheet()->setCellValue('Y4', $l_start_date);

	
	$objPHPExcel->getActiveSheet()->getStyle('A5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->getRowDimension('5')->setRowHeight(40);
	$objPHPExcel->getActiveSheet()->setCellValue('A5', "(2)");
	$objPHPExcel->getActiveSheet()->getStyle('B5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('B5', "(3)");
	$objPHPExcel->getActiveSheet()->getStyle('C5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('C5', "(4)");
	//$objPHPExcel->getActiveSheet()->getStyle('D5')->applyFromArray($styleArray1);
	//$objPHPExcel->getActiveSheet()->setCellValue('D5', "");
	$objPHPExcel->getActiveSheet()->getStyle('D5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('D5', "(5)");
	$objPHPExcel->getActiveSheet()->getStyle('E5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('E5', "(6)");
	$objPHPExcel->getActiveSheet()->getStyle('F5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('F5', "(7)");
	$objPHPExcel->getActiveSheet()->getStyle('G5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('G5', "(8)");
	$objPHPExcel->getActiveSheet()->getStyle('H5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('H5', "(9)");
	$objPHPExcel->getActiveSheet()->getStyle('I5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('I5', "(10)");
	$objPHPExcel->getActiveSheet()->getStyle('J5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('J5', "(11)");
	$objPHPExcel->getActiveSheet()->getStyle('K5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('K5', "(12)");
	$objPHPExcel->getActiveSheet()->getStyle('L5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('L5', "(13)");
	$objPHPExcel->getActiveSheet()->getStyle('M5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('M5', "(14)=[(5)+(6) +(11)+(12)+(13)]/(4)");
	$objPHPExcel->getActiveSheet()->getStyle('N5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('N5', "(15)=(14) x [(4)-(7)]");
	$objPHPExcel->getActiveSheet()->getStyle('O5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('O5', "(16)");
	$objPHPExcel->getActiveSheet()->getStyle('P5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('P5', "(17)");
	$objPHPExcel->getActiveSheet()->getStyle('Q5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('Q5', "(18)");
	$objPHPExcel->getActiveSheet()->getStyle('R5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('R5', "(19)");
	$objPHPExcel->getActiveSheet()->getStyle('S5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('S5', "(20)");
	
	$objPHPExcel->getActiveSheet()->getStyle('T5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('T5', "(21)= 240000x(20)");
	
	$objPHPExcel->getActiveSheet()->getStyle('U5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('U5', "(22)=(15) +(16)+(17) +(18)+(19)+(21)");
	$objPHPExcel->getActiveSheet()->getStyle('V5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('V5', "(23)");
	
	$objPHPExcel->getActiveSheet()->getStyle('W5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('W5', "(24)=(22)-(23)");
	$objPHPExcel->getActiveSheet()->getStyle('X5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('X5', "");
	$objPHPExcel->getActiveSheet()->getStyle('Y5')->applyFromArray($styleArray1);
	$objPHPExcel->getActiveSheet()->setCellValue('Y5', "");
	
	//$sum_received=0;
	$key=6;
	
	foreach ($_SESSION['emsa'] as $khoa =>  $giatri){
		$objPHPExcel->getActiveSheet()->getRowDimension($key)->setRowHeight(20);
		$objPHPExcel->getActiveSheet()->getStyle('A'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->setCellValue('A'.$key, $giatri['name']);
		
		$objPHPExcel->getActiveSheet()->getStyle('B'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->setCellValue('B'.$key, $giatri['position']);
		
		$objPHPExcel->getActiveSheet()->getStyle('C'.$key)->applyFromArray($styleArray2);
		//$objPHPExcel->getActiveSheet()->setCellValue('C'.$key, $giatri[really_number_time_work]."/".$giatri[number_time_work]);
		$objPHPExcel->getActiveSheet()->setCellValue('C'.$key, $giatri['really_number_time_work']);
		
		$objPHPExcel->getActiveSheet()->getStyle('D'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('D'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('D'.$key, ($giatri['basic_salary']));
		
		$objPHPExcel->getActiveSheet()->getStyle('E'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('E'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('E'.$key, ($giatri['allowance_basic_salary']));
		
		$objPHPExcel->getActiveSheet()->getStyle('F'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->setCellValue('F'.$key, $giatri['number_dateoff']);
		
		$objPHPExcel->getActiveSheet()->getStyle('G'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->setCellValue('G'.$key, $giatri['number_holiday']);
		
		$objPHPExcel->getActiveSheet()->getStyle('H'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->setCellValue('H'.$key, $giatri['number_is_comeback_early']);
		
		$objPHPExcel->getActiveSheet()->getStyle('I'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->setCellValue('I'.$key, $giatri['number_is_late']);
		
		$objPHPExcel->getActiveSheet()->getStyle('J'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('J'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('J'.$key,$giatri['allowance_longyear']);
		
		$objPHPExcel->getActiveSheet()->getStyle('K'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('K'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('K'.$key, ($giatri['allowance_senior']));
		
		$objPHPExcel->getActiveSheet()->getStyle('L'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('L'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('L'.$key, ($giatri['allowance_c']));
		
		$objPHPExcel->getActiveSheet()->getStyle('M'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('M'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('M'.$key,'=(D'.$key.'+E'.$key.'+J'.$key.'+K'.$key.'+L'.$key.')/'.$giatri['number_time_work']);
		
		//=(E'.$key.'+F'.$key.'+K'.$key.'+L'.$key.')/'.$giatri[number_time_work]);
		
		$objPHPExcel->getActiveSheet()->getStyle('N'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('N'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('N'.$key,'=IF(G'.$key.'>1,M'.$key.'*(IF((C'.$key.')>25,25,C'.$key.')-F'.$key.'-(G'.$key.'-1)) ,M'.$key.'*(IF((C'.$key.')>25,25,C'.$key.')-F'.$key.'))');
		
		//=IF((FLOOR(I'.$key.'/4,0.5)+H'.$key.')>1,M'.$key.'*(IF((C'.$key.'+D'.$key.')>25,25,C'.$key.'+D'.$key.')-G'.$key.'-((FLOOR(I'.$key.'/4,0.5)+H'.$key.')-1)),M'.$key.'*(IF((C'.$key.'+D'.$key.')>25,25,C'.$key.'+D'.$key.')-G'.$key.'))');
		
		
		$objPHPExcel->getActiveSheet()->getStyle('O'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('O'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('O'.$key, ($giatri['allowance_holiday']));
		
		$objPHPExcel->getActiveSheet()->getStyle('P'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('P'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('P'.$key, '=IF((FLOOR(H'.$key.'/4,0.5)+G'.$key.')>1,26000*(IF((C'.$key.')>25,25,C'.$key.')-F'.$key.'-((FLOOR(H'.$key.'/4,0.5)+G'.$key.')-1)),26000*(IF((C'.$key.')>25,25,C'.$key.')-F'.$key.'))');
		
		//=IF((FLOOR(I'.$key.'/4,0.5)+H'.$key.')>1,26000*(IF((C'.$key.'+D'.$key.')>25,25,C'.$key.'+D'.$key.')-G'.$key.'-((FLOOR(I'.$key.'/4,0.5)+H'.$key.')-1)),26000*(IF((C'.$key.'+D'.$key.')>25,25,C'.$key.'+D'.$key.')-G'.$key.'))');
		
		$objPHPExcel->getActiveSheet()->getStyle('Q'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('Q'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('Q'.$key, '=IF((FLOOR(H'.$key.'/4,0.5)+G'.$key.')>1,4000*(IF((C'.$key.')>25,25,C'.$key.')-F'.$key.'-((FLOOR(H'.$key.'/4,0.5)+G'.$key.')-1)),4000*(IF((C'.$key.')>25,25,C'.$key.')-F'.$key.'))');
		
		//=IF((FLOOR(I'.$key.'/4,0.5)+H'.$key.')>1,4000*(IF((C'.$key.'+D'.$key.')>25,25,C'.$key.'+D'.$key.')-G'.$key.'-((FLOOR(I'.$key.'/4,0.5)+H'.$key.')-1)),4000*(IF((C'.$key.'+D'.$key.')>25,25,C'.$key.'+D'.$key.')-G'.$key.'))');
		
		$objPHPExcel->getActiveSheet()->getStyle('R'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('R'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('R'.$key, ($giatri['allowance_hard']));
		
		$objPHPExcel->getActiveSheet()->getStyle('S'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->setCellValue('S'.$key, $giatri['number_overtime']);
		
		$objPHPExcel->getActiveSheet()->getStyle('T'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('T'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('T'.$key, '=240000*S'.$key.'');
		
		
		
		
		$objPHPExcel->getActiveSheet()->getStyle('U'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('U'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('U'.$key, '=N'.$key.'+O'.$key.'+P'.$key.'+Q'.$key.'+R'.$key.'+T'.$key.'');
		
		//=N'.$key.'+O'.$key.'+P'.$key.'+Q'.$key.'+R'.$key.'+T'.$key.'');
		
		$objPHPExcel->getActiveSheet()->getStyle('V'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('V'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('V'.$key, ($giatri['insurance']));
		
		
		$objPHPExcel->getActiveSheet()->getStyle('W'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->getStyle('W'.$key)->getNumberFormat()->setFormatCode('#,##0');
		$objPHPExcel->getActiveSheet()->setCellValue('W'.$key, '=U'.$key.'-V'.$key.'');
		
		$objPHPExcel->getActiveSheet()->getStyle('X'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->setCellValue('X'.$key, $giatri['note']);
		
		$objPHPExcel->getActiveSheet()->getStyle('Y'.$key)->applyFromArray($styleArray2);
		$objPHPExcel->getActiveSheet()->setCellValue('Y'.$key, $giatri['StartDate']);
		$key++;
		//$sum_received +=$giatri[received_salary];
	}
	
	$objPHPExcel->getActiveSheet()->getStyle('W'.$key)->applyFromArray($styleArray2);
	$objPHPExcel->getActiveSheet()->getStyle('W'.$key)->getNumberFormat()->setFormatCode('#,##0');
	$objPHPExcel->getActiveSheet()->setCellValue('W'.$key, '=SUM(W6:W'.($key-1).')');
	
	include 'PHPExcel/IOFactory.php';
	
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	header("Content-type: application/vnd.ms-excel");
	header('Content-Disposition: attachment;filename="' . $filename);
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	$objWriter->save('php://output');
}
exit;

?>

